using System;
using System.Collections.Generic;

namespace Verse;

public static class GameComponentUtility
{
	public static void GameComponentUpdate()
	{
		List<GameComponent> components = Current.Game.components;
		for (int i = 0; i < components.Count; i++)
		{
			try
			{
				components[i].GameComponentUpdate();
			}
			catch (Exception ex)
			{
				Log.Error(ex.ToString());
			}
		}
	}

	public static void GameComponentTick()
	{
		List<GameComponent> components = Current.Game.components;
		for (int i = 0; i < components.Count; i++)
		{
			try
			{
				components[i].GameComponentTick();
			}
			catch (Exception ex)
			{
				Log.Error(ex.ToString());
			}
		}
	}

	public static void GameComponentOnGUI()
	{
		List<GameComponent> components = Current.Game.components;
		for (int i = 0; i < components.Count; i++)
		{
			try
			{
				components[i].GameComponentOnGUI();
			}
			catch (Exception ex)
			{
				Log.Error(ex.ToString());
			}
		}
	}

	public static void FinalizeInit()
	{
		List<GameComponent> components = Current.Game.components;
		for (int i = 0; i < components.Count; i++)
		{
			try
			{
				components[i].FinalizeInit();
			}
			catch (Exception ex)
			{
				Log.Error(ex.ToString());
			}
		}
	}

	public static void StartedNewGame()
	{
		List<GameComponent> components = Current.Game.components;
		for (int i = 0; i < components.Count; i++)
		{
			try
			{
				components[i].StartedNewGame();
			}
			catch (Exception ex)
			{
				Log.Error(ex.ToString());
			}
		}
	}

	public static void LoadedGame()
	{
		List<GameComponent> components = Current.Game.components;
		for (int i = 0; i < components.Count; i++)
		{
			try
			{
				components[i].LoadedGame();
			}
			catch (Exception ex)
			{
				Log.Error(ex.ToString());
			}
		}
	}
}
